package net.dfrz.oa.dao.repository;

import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import net.dfrz.oa.dao.repository.support.BaseRepository;
import net.dfrz.oa.pojo.User;

/*
 * 
 * springData继承repository 自动被spring容器管理,不需要写实现类
 * 1.方法命名需按一定的规范
 */
public interface UserRepository extends BaseRepository<User>{

	User getByUsernameAndPassword(String username,String password);

	@Modifying
	@Query("UPDATE User u SET u.name=:name,u.sex=:sex,u.major=:major,u.edu=:edu,u.school=:school WHERE u.id=:id")
	void updateUserInfo(@Param("id")Integer id, @Param("name")String name, @Param("sex")String sex, @Param("major")String major,
			@Param("edu")String edu, @Param("school")String school);
	
	@Modifying
	@Query("UPDATE User u SET u.password=:password WHERE u.id=:id")
	void editPassword(@Param("id")Integer uid, @Param("password")String newPwd);
}
